home *** CD-ROM | disk | FTP | other *** search
- Path: nntp-trd.UNINETT.no!usenet
- From: Paul Kenneth Egell-johnsen <paulken4@afrodite.kih.no>
- Newsgroups: comp.lang.c++
- Subject: Re: Template declaration in h file and cpp fil
- Date: Thu, 07 Mar 1996 09:18:13 +0100
- Organization: UNINETT news service
- Message-ID: <313E9BC5.2DF2@afrodite.kih.no>
- References: <4hhafd$f8d@academy.bastad.se> <Pine.SOL.3.91.960305172908.17346D-100000@hamlet.uncg.edu>
- NNTP-Posting-Host: afrodite.kih.no
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: quoted-printable
- X-Mailer: Mozilla 2.0 (X11; I; HP-UX A.09.05 9000/720)
-
- QIAN . ZHONG wrote:
- > =
-
- > =
-
- > =
-
- > On Tue, 5 Mar 1996, Mikael Bergqvist wrote:
- > =
-
- > > Hi!
- > >
- > > I=B4m having a problem with the following code:
- > >
- > > SORT.H:
- > >
- > > template <class TArray>
- > > void QSort(int lo,int hi,TArray *array);
- > >
- > > END SORT.H
- > >
- > > SORT.CPP
- > > #include "sort.h"
- > > template <class TArray>
- > > void QSort(int lo,int hi,TArray *array)
- > > {
- > >
- > > ..... some code
- > > }
- > >
- > > END SORT.CPP
- > >
- > > TEST.CPP
- > >
- > > #include "sort.h"
- > >
- > > int main(void)
- > > {
- > > int array[10]=3D{.........};
- > > QSort(0,9,array);
- > > }
- > >
- > > END TEST.CPP
- > >
- > > The problem is that the linker returns the following error:
- > > Undefinded symbol QSort(int,int,int far *); in module test.cpp
- > >
- > > This problem doesent occur if the main function is in SORT.CPP below
- > > the QSort function.
- > >
- > > HELP!
- > >
- > > /Mikael
- > >
- > =
-
- > You should put SORT.CPP into SORT.H and include SORT.H into
- > every .CPP files.
- > =
-
- No! You should make a makefile, perhaps a SORT library
- (precompile the class). It is easier to put SORT.CPP inn i
- SORT.H, I'll grant you that, but it is contrary to the intents
- of headerfiles and implementationfiles.
-
- And if you are going to reuse your classes, you would like to
- precompile them, in order to just linking them into your code
- later.
-
- Sorry, no help on that subject from me, I just tried it out
- until i found a good solution, but I can say this:
-
- On unix use mkmf to make a makefile. Then go into the file and
- look for obvious mistakes, or paths which are missing or wrong.
- When you have done your enhancements, you may use mkmf each time
- you add a new .h or .cpp file, and the EARLIER changes you have
- done will not be void!
- In larger packages (Visual C++, Borland and such) there should
- be some sort of projectmanagement which will help you out.
- On other systems, try the unix way (on Mac, the package way).
- On the Amiga SAS/C the mkmf program is called makemf.
-
- After makinkg a makefile, just type make in the apropriate
- directory, and your program should compile!
-
- Paul K Egell-Johnsen,
-
- mailto:paulken4@afrodite.kih.no
- http://afrodite.kih.no:8001/studenter/paulken4/frames/
-